//
//  TKYResponsibilityHandleController.m
//  StationHouseHelper
//
//  Created by apple on 2018/6/26.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYResponsibilityHandleController.h"

@interface TKYResponsibilityHandleController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UILabel *stringlenghtLab;
@property (weak, nonatomic) IBOutlet UITextView *textView;


@end

@implementation TKYResponsibilityHandleController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    // Do any additional setup after loading the view from its nib.
}

/**
 设置界面
 */
- (void)setupUI{
    self.navigationItem.title = @"安全问题";
    self.navigationController.navigationBar.barTintColor = KNavColor;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(sendAction:)];
    
    self.textView.delegate = self;
    self.descLabel.userInteractionEnabled = NO;
}


- (void)sendAction:(UIBarButtonItem *)barButtonItem{
    
    NSLog(@"发送");
    
}

-(void)textViewDidChange:(UITextView *)textView
{
    self.descLabel.text = @"";
    self.descLabel.hidden = YES;
    //实时显示字数
    self.stringlenghtLab.text = [NSString stringWithFormat:@"%ld/300",(long)textView.text.length];
    
    //字数限制
    if (textView.text.length >= 300) {
        textView.text = [textView.text substringToIndex:300];
    }
    
    //取消按钮点击权限，并显示文字
    if (textView.text.length == 0) {
        self.descLabel.hidden = NO;
        
    }
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        
        [self.textView resignFirstResponder];
        
        return NO;
    }
    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
